package work.mediway.bi.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mediway.hos.base.model.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import work.mediway.bi.model.dto.DataSetConfigDTO;
import work.mediway.bi.model.entity.DatasetConfig;
import work.mediway.bi.model.vo.DataSetConfigVO;
import work.mediway.bi.service.DatasetConfigService;

import javax.annotation.Resource;

/**
 * @author bovane <bovane.ch@gmail.com>
 * @description
 * @create 2023-07-10 10:03
 */
@Slf4j
@RestController
@RequestMapping("/bi/dataset/config")
public class BiDesignDataSetConfigController {

    @Resource
    DatasetConfigService datasetConfigService;

    /**
     * 获取数据集配置详细信息
     */
    @GetMapping()
    public BaseResponse getInfo(DataSetConfigDTO dataSetConfigDTO) {
        IPage<DataSetConfigVO> result = this.datasetConfigService.getDataSetConfigInfo(dataSetConfigDTO);
        return BaseResponse.success(result);
    }

    /**
     * 新增数据集配置详细信息
     */
    @PostMapping
    public BaseResponse add(@RequestBody @Validated DatasetConfig datasetConfig) {
        //保存基本信息
        Boolean result = this.datasetConfigService.addDatasetConfig(datasetConfig);
        return result ? BaseResponse.success(): BaseResponse.error();
    }

    /**
     * 更新数据集配置详细信息
     */
    @PutMapping
    public BaseResponse edit(@RequestBody @Validated DatasetConfig datasetConfig) {
        Boolean result = this.datasetConfigService.updateDatasetConfig(datasetConfig);
        return result ? BaseResponse.success(): BaseResponse.error();
    }

    /**
     * 删除数据集配置详细信息,多条则以 "," 作为分割
     */
    @DeleteMapping("/{ids}")
    public BaseResponse remove(@PathVariable String ids) {
        this.datasetConfigService.deleteDatasetConfig(ids);
        return BaseResponse.success();
    }
}
